﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MuddyBoots.GreenlightQC.Mobile.Persistence
{
    public class DatabaseEntities : IDatabaseEntities
    {
        public IEnumerable<QRY_Menu_Result> GetMenu(int applicationId)
        {
            using (var context = new GreenlightQCMobileEntities())
            {
                foreach (var menuResult in context.QRY_Menu(applicationId))
                {
                    yield return menuResult;
                }
            }
        }

        public IEnumerable<QRY_User_Validate_Result> ValidateCredentials(string username, string password, string pin)
        {
            using (var context = new GreenlightQCMobileEntities())
            {
                return context.QRY_User_Validate(username, password, "WFT?");
            }
        }

        public int GetFailedLoginCount(int userId)
        {
            using (var context = new GreenlightQCMobileEntities())
            {
                var result = context.QRY_User_GetFailedLoginCount(userId).FirstOrDefault();
                return result.GetValueOrDefault(0);
            }
        }
    }
}
